from typing import List


class Solution:
    def isValid(self,s):
        stack = []
        map = {}
        for x in s:
            if x in map:
                stack.append(map[x])
            else:
                if len(stack) == 0:
                    return False
                else:
                    top = stack.pop()
                    if (top == x):
                        continue
                    else:
                        return False
        return len(stack) == 0

    def getLength(self,s):
        if len(s) > 0:
            short = 0
            for i in range(1,len(s)):
                if s[short] != s[i]:
                    short+=1
                    s[short] = s[i]

            return short+1
        else:
            return len(s)

    def mergeArray(self,nums1,m,nums2,n):
        while(m > 0 and n >0):
            if(nums1[m-1] > nums2[n-1]):
                nums1[m+n-1] = nums1[m-1]
                m-=1
            else:
                nums1[m+n-1] = nums2[n-1]
                n-=1
        if n > 0:
          nums1[:n] = nums2[:n]

    def maxProfit(self,prices):
        if not prices: return 0
        min_price = float('inf')
        max_profit = 0
        for price in prices:
            if  price < min_price:
                min_price = price
            elif max_profit < price - min_price:
                max_profit = price - min_price
        return max_profit

    def sumProfit(self,prices):
        profit = [prices[i] -prices[i-1] for i in range(len(prices)) if prices[i] > prices[i-1]]
        return sum(profit)

    def isP2(self,s):
        new_s = ''.join(i for i in s if i.isalnum().lower())
        return new_s == s[::-1]

    def isP1(self,s):
        left = 0
        right = len(s) -1
        while left < right:
            if not s[left].isalnum():
                continue
            if not s[right].isalnum():
                continue
            if s[left].lower() == s[right].lower():
                left+=1
                right-=1

            else:
                break;
        return left>=right


    def singlenum(self,nums):
        singlenum = 0
        for num in nums:
            singlenum ^=num
        return singlenum



















